<?php

include "../controller/ConectBanco.php";

$idDevice = $_GET["idDevice"];

$result = mysql_query("SELECT realDateTime, typeData, latitude, longitude,velocidade,idDevice,idPackage
						FROM package 
						WHERE idDevice = $idDevice
						 AND realDateTime  = (SELECT max(realDateTime)
		                                        FROM package 
											   WHERE idDevice = $idDevice)")or die (mysql_error());

header("Content-Type: application/json");
$jsonData = '{"posicao":[';
while($row = mysql_fetch_array($result)){

				$jsonData .= '{"idPackage"  :'.$row["idPackage"].',
							   "typeData"   :'.$row["typeData"].',
		                       "latitude"   :"'.$row["latitude"].'",
		                       "longitude"  :"'.$row["longitude"].'",
		                       "velocidade" :"'.$row["velocidade"].'",
							   "dateTime"   :"'.$row["realDateTime"].'"},';
}	
$jsonData = chop($jsonData,",");
$jsonData .= ']}';

echo $jsonData;

?>